package com.example.design.nioandnettty.practice.任务队列;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * @Description TODO
 * @date 2023/9/22 9:10
 * @Author liuzhihui
 * @Version 1.0
 */
public class NettyClientTaskQueue {

    public static void main(String[] args) throws InterruptedException {
        NioEventLoopGroup eventExecutors = new NioEventLoopGroup();

        Bootstrap bootstrap = new Bootstrap();
        ChannelFuture channelFuture = bootstrap.group(eventExecutors)
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new NettyClientTaskQueueHandler());
                    }
                }).connect("127.0.0.1", 6666).sync();

        channelFuture.channel().closeFuture().sync();
        eventExecutors.shutdownGracefully();
    }
}
